<template>
  <div class="hello">
    <input type="file" name="" @change="onChange" id="file" />
  </div>
</template>

<script>
import { read, utils } from 'xlsx';
export default {
  name: 'HelloWorld',
  props: {
    msg: String,
  },
  methods: {
    async onChange(e) {
      const file = e.target.files[0]; //上传的文件
      const reader = new FileReader();

      reader.readAsBinaryString(file); //读取文件内容 *注意这是一个异步操作

      reader.onload = (e) => {
        const data = e.target.result;

        const zzexcel = read(data, {
          type: 'binary',
        });

        let result = [];

        for (let i = 0; i < zzexcel.SheetNames.length; i++) {
          const newData = utils.sheet_to_json(zzexcel.Sheets[zzexcel.SheetNames[i]]);
          result.push(...newData);
        }
        console.log(result);
      };
    },
  },
};
</script>
